package com.findyou.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @Title: JDBCConfig
 * @Author 贾金博
 * @Package com.findyou.config
 * @Date 2024/11/22 上午8:41
 * @description: jdbc的配置类
 */
@Configuration
@PropertySource("classpath:JDBC.properties")  // 加载外部配置文件 JDBC.properties
public class JDBCConfig {
    @Value("${jdbc.driverClassName}")
    private String driverClassName;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Bean // 类似咱们之前的<bean>标签
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;// 返回值会被加入到spring的容器里面
    }
}
